//
//  Module.m
//  CocoaSynth
//
//  Created by Jérémy Brault on 17/02/10.
//  Copyright 2010 None. All rights reserved.
//

#import "Module.h"

#import "PortOutProtocol.h"

@implementation Module

#pragma mark -
#pragma mark Accessors

@synthesize portIn, portsOut, inputSample;

#pragma mark -
#pragma mark Memory Management

- (id)init
{
	if (self = [super init]) {
		portIn = nil;
		portsOut = [[NSMutableArray alloc] init];
		inputSample = nil;
	}
	
	return self;
}

- (void)dealloc 
{
	[portIn release];
	portIn = nil;
	
	[portsOut release];
	portsOut = nil;
	
	[inputSample release];
	inputSample = nil;
	
	[super dealloc];
}

#pragma mark -
#pragma mark Module

- (void)read
{
	[self setInputSample:[portIn getSample]];
}

- (void)compute
{
	for (id<PortOutProtocol> portOut in portsOut) {
		if ([portOut isConnected]) {
			[portOut executeStrategy];
		}
	}
}

- (void)stop
{
	
}

- (void)addPortOut:(id<PortOutProtocol>)aPortOut
{
	[portsOut addObject:aPortOut];
}
	
- (void)removePortOut:(id<PortOutProtocol>)aPortOut
{
	[portsOut removeObject:aPortOut];
}

@end
